package com.chance.cc.crawler.development.bootstrap.weibo.invitation;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;
import org.junit.Test;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;

import static com.chance.cc.crawler.core.CrawlerEnum.CrawlerRequestType.*;

/**
 * @ClassName weibo
 * @Description TODO
 * @Author songding
 * @Date 2021/10/8 9:26
 * @Version 1.0
 * 微博帖子自主开发
 *
 **/
public class WeiboInvitationStart {
    private static final String domain = "weibo";
    private static final String site = "invitation";
    private static final Map<String,String> cookieMap = new HashMap<>();
    private static final String cookie = "_2A25MVrUDDeRhGeNI7lYR-S_Fwz-IHXVvuNtLrDV8PUJbkNANLVmkkW1NSExA2JFf5T7pSaFeSBmHX3qvqAFPvWoG";
    public static void main(String[] args) {
        limit();
    }

    public static void limit(){
        String url = "https://s.weibo.com/weibo/%2523%25E4%25BA%25A4%25E8%25AD%25A6%25E5%259C%25A8%25E6%259C%258B%25E5%258F%258B%25E5%259C%2588%25E6%2599%2592%25E6%2594%25B6%25E5%2588%25B0%25E7%259A%2584%25E9%259B%25A8%25E4%25BC%259E%2523?" +
                "q=%23%E9%95%BF%E6%B4%A5%E6%B9%96%E5%BD%B1%E8%AF%84%23" +
                "&typeall=1&suball=1&timescope=custom:2021-10-01:2021-10-08&Refer=g";
        //String url = "https://weibo.com/u/2789987841";
        CrawlerRequestRecord requestRecord = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpUrl(url)
                .httpConfig(HttpConfig.me(domain))
                .recordKey(url)
                .releaseTime(System.currentTimeMillis())
                .httpCookie("SUB",cookie)
                .filter(CrawlerEnum.CrawlerRecordFilter.key)
                .addFilterInfo(FilterUtils.memoryFilterKeyInfo(domain))
                .needWashed(true)
                .build();

        requestRecord.tagsCreator().bizTags().addDomain(domain);
        requestRecord.tagsCreator().bizTags().addSite(site);
        requestRecord.tagsCreator().bizTags().addCustomKV("startTime","2021-09-14");
        requestRecord.tagsCreator().bizTags().addCustomKV("endTime","2021-09-27");
        //关键词
        CrawlerRequestRecord keywordRecord = CrawlerRequestRecord.builder()
                .startPageRequest("keyword",turnPageItem)
                .httpUrl("")
                .requestLabelTag(supportSource)
                .requestLabelTag(internalDownload)
                .build();

        DevCrawlerController.builder()
                .triggerInfo(domain,domain,System.currentTimeMillis(),domain)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline()
                .fileResultPipeline("F:\\chance_log\\weibo\\weibo.log",true)
                .requestRecord(requestRecord)
                //.supportRecord(keywordRecord)
                .build("com.chance.cc.crawler.development.scripts.weibo")
                .start();

    }
    static {
        cookieMap.put("SUB",cookie);
    }
    @Test
    public void test(){
        String q = URLEncoder.encode("#长津湖影评#");
        System.out.println(q);
    }
}
